from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time
testCase="DBshop008_销售管理退货管理搜索"
text="不喜欢，退货"
# 已购买商品点击退货
rootPath=get_pro_rootpath()
orderID=readFile(rootPath+r'\public\order1.txt')
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
# 添加退货信息
firefox.find_element_by_link_text("用户中心").click()
firefox.find_element_by_link_text("退货申请").click()
firefox.find_element_by_partial_link_text("点此申请退货").click()
firefox.find_element_by_id("order_sn").send_keys(orderID)
firefox.find_element_by_id("search-order").click()
firefox.find_element_by_xpath("//input[@value='1']").click()
firefox.find_element_by_id("refund_info").send_keys(text)
time.sleep(1)
firefox.find_element_by_xpath("//button[text()='申请退货']").click()
time.sleep(1)
firefox.switch_to.alert.accept()
time.sleep(2)
firefox.quit()
# 1.点击销售管理退货管理。
firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox, "销售管理", "退货管理")
# 2.点击退货方式，选择框选择“退货到账户余额”点击“搜索”按钮。
firefox.find_element_by_xpath("//select[@name='refund_type']/option[@value='1']").click()
firefox.find_element_by_xpath("//button").click()
if firefox.find_element_by_xpath(
    "//td[text()='%s']/following-sibling::td[5]/a[2]"%orderID).is_displayed():
    writeLog("%s 测试通过"%testCase)
else:
    writeLog("%s 测试失败"%testCase)
    getPhoto(firefox)
firefox.quit()

